﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoCharacterInventory : SignedApiCall
    {
        public IEnumerable<ApiItem> Items { get; private set; }

        public ApiInfoCharacterInventory()
        {
        }

        public ApiInfoCharacterInventory(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int characterId)
        {
            LoadSignedApiCall(string.Format("characterId={0}", characterId));

            XmlNodeList characterNodes = XmlDocument.GetElementsByTagName("a:stats_character_inventoryResult");
            List<ApiItem> items = new List<ApiItem>();
            foreach (XmlNode characterNode in characterNodes)
            {
                items.Add(new ApiItem(characterNode.CreateNavigator().ReadSubtree()));
            }
            Items = items;
        }

        protected override string ApiCallName
        {
            get { return "CharacterInventory"; }
        }
    }
}
